<?php

	session_start();
	
	if(isset($_SESSION['UserId']))
	{
		header('Location: home.php');
   		exit();
	}
	
	include_once ('../Functions/SecureFunctions.php'); //contains login functions
	
	if(isset($_REQUEST['Email']))
	{
		if(!$ValidationErrors = Login($_REQUEST['Email'], $_REQUEST['Password']))
			header("Location: home.php");		
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		
		<?php if (isset($ValidationErrors) && count($ValidationErrors) > 0 ) { ?> 
			$("#<?php echo $ValidationErrors[0]?>").css('color', 'red');
			$("#<?php echo $ValidationErrors[1]?>").css('border', '1px solid red');
		<?php } else { ?>
			document.getElementById("Email").focus();
		<?php } ?>
	});
</script>
<link rel="stylesheet" type="text/css" href="../Styler.css"/>	
</head>

<body>

	<div id="header"></div>

	<div id="login">
	     
	   	<?php if(isset($ValidationErrors)) {?> 
		     
		    <div class="errorLogin">
		        <?php echo $ValidationErrors[2];?>
		    </div>
		    <script type="text/javascript">
		    	
		    </script>
	    <?php } ?>
	    
		<form method="post">
			<div>
				Login
			</div>
	        <div>
	            <span><label for="Email" id="loginEmail">Email:</label></span>
	        </div>
	        <div>
	            <input type="text" name="Email"	id="Email" <?php if (isset($_REQUEST['Email'])) { ?> value="<?php echo $_REQUEST['Email'];?>" <?php }?>/>
	        </div>
	        <div>
	            <span><label for="Password" id="loginPass">Password:</label></span>
	        </div>
	        <div>
	            <input type="password" name="Password" id="Password"/>
	        </div>
	        <input type="submit" value="Login" class="loginButton" id="submitButton"/> <!-- class="finishButton" -->
	       <!-- <a href="lost.php">Forgot your password</a>-->
	    </form>
    </div>
</body>
</html>